package com.study.algorithm.sort;

/**
 * 插入排序
 */
public class InserctionSort {
    public static void   main(String args[]){
        insertSort(new int[]{4,3,2,1});
    }

    static void insertSort(int[] nums){
        int size = nums.length;
        for (int i = 1; i < size; i++){

            //要进行插入的数
            int temp = nums[i];
            int j = i;

            while (j > 0){
                //比较置换
                if(temp < nums[j -1 ]){
                    nums[j] = nums[j-1];
                }
                j--;
            }

            if(j != i){
                nums[j] = temp;
            }
            PrintUtils.printArray(nums);
        }
    }
}
